<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>首页</title>
    <link rel="stylesheet" type="text/css" href="../../css/aui/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui/aui-slide.css" />
    <style>
        #header {
            display: flex;
            align-items: center;
            padding: .75rem .75rem;
        }

        #header .logo {
            width: 4.5rem;
            margin-right: 1rem;
        }

        #header .location img {
            width: 1.5rem;
            display: inline-block;
            vertical-align: middle;
            margin-right: .3rem;
        }

        #header .location span {
            font-weight: bold;
            font-size: .85rem;
        }

        #header .location i {
            font-weight: bold;
            font-size: .5rem;
            margin-left: .3rem;
        }

        .iconimg {
            width: 3.4rem;
            display: inline-block;
        }

        .aui-grid [class*=aui-col-] {
            padding: 0.5rem 0;
        }

        #notice {
            height: 2rem;
            background: #0689FB;
            display: flex;
            padding: .3rem 1rem;
            align-items: center;
        }

        #notice-slide {
            width: 100%;
            height: calc(2rem - 0.6rem);
        }

        #notice-slide .aui-slide-node {
            border-radius: .1rem;
            color: #AFAFAF;
            font-size: .7rem;
        }

        .advertising_slide {
            /*margin-top: .75rem;*/
            margin-bottom: 3rem;
        }

        .advertising_slide img {
            width: 100%;
            margin-top: .75rem;
        }
    </style>
</head>

<body>
    <div class="aui-content" id="app">
        <!-- 顶部 -->
        <div id="header">
            <div class="logo"><img src="../../image/icon/logo.png" alt=""></div>
            <div class="location" @click="openCity()"><img src="../../image/icon/daohang.png" alt="">
                <span>
                {{userRegion.area}}
                <i class="aui-iconfont aui-icon-down"></i>
              </span>
            </div>
        </div>

        <!-- 轮播 -->
        <div id="aui-slide">
            <div class="aui-slide-wrap">
                <div class="aui-slide-node" v-for="bannerList in bannerData"><img :src="bannerList.cover_imgurl" :alt="bannerList.title"></div>
            </div>
            <div class="aui-slide-page-wrap">
                <!--分页容器-->
            </div>
        </div>
        <!-- 公告 -->
        <div id="notice">
            <div style="width:18%;"><img src="../../image/img/notice.png" alt="" style="width:70%;"></div>
            <div id="notice-slide">
                <div class="aui-slide-wrap">
                    <div class="aui-slide-node aui-slide-node-middle aui-slide-node-center" onclick="openWin('notice_list_win', './notice/notice_list_win.html');" v-for="noticeList in noticeData">
                        {{noticeList.title}}
                    </div>
                </div>
            </div>
        </div>
        <!-- 宫格菜单 -->
        <section class="aui-grid">
            <div class="aui-row">
                <div class="aui-col-xs-3" onclick="openWin('platform_introduction_list', './platform_introduction/platform_introduction_list_win.html');">
                    <img src="../../image/icon/lanmu01.png" class="iconimg" alt="">
                    <div class="aui-grid-label">平台介绍</div>
                </div>
                <div class="aui-col-xs-3">
                    <img src="../../image/icon/lanmu02.png" class="iconimg" alt="" @click="lookingForWorkers()">
                    <div class="aui-grid-label">工人资源</div>
                </div>
                <div class="aui-col-xs-3" onclick="openWin('type_win', './bus_res/type_win.html');">
                    <img src="../../image/icon/lanmu03.png" class="iconimg" alt="">
                    <div class="aui-grid-label">业务资源</div>
                </div>
                <div class="aui-col-xs-3" onclick="openWin('shop_type_win', './shop_res/shop_type_win.html')">
                    <!-- <div class="aui-col-xs-3" onclick="$toast('正在开发中...');"> -->
                    <img src="../../image/icon/lanmu04.png" class="iconimg" alt="">
                    <div class="aui-grid-label">商品资源</div>
                </div>
                <div class="aui-col-xs-3" onclick="openWin('shop_type_win', './instructions/instructions_list_win.html')">
                    <img src="../../image/icon/lanmu05.png" class="iconimg" alt="">
                    <div class="aui-grid-label">操作指南</div>
                </div>
                <div class="aui-col-xs-3" onclick="openWin('type_win', './transactions/type_win.html')">
                    <img src="../../image/icon/lanmu06.png" class="iconimg" alt="">
                    <div class="aui-grid-label">二手交易</div>
                </div>
                <div class="aui-col-xs-3" onclick="openWin('odd_job_list_win', './odd_job/odd_job_list_win.html')">
                    <img src="../../image/icon/lanmu07.png" class="iconimg" alt="">
                    <div class="aui-grid-label">找零工</div>
                </div>
                <!-- <div class="aui-col-xs-3" onclick="openWin('platform_rights_list', './platform_rights/platform_rights_list_win.html')">
                    <img src="../../image/icon/lanmu08.png" class="iconimg" alt="">
                    <div class="aui-grid-label">平台权益</div>
                </div> -->
                <div class="aui-col-xs-3" onclick="$toast('更多功能正在建设中...')">
                    <img src="../../image/icon/more.png" class="iconimg" alt="">
                    <div class="aui-grid-label">更多</div>
                </div>
            </div>
        </section>
        <!-- 广告 -->
        <div class="advertising_slide" id="advertising_slide">
            <img style="height:190px;" v-for="advertisingList in advertisingData" :src="advertisingList.cover_imgurl" alt="" @click="openAdvertising({id: advertisingList.advert_id});">
            <!-- <div class="aui-slide-wrap">
                <div class="aui-slide-node" v-for="advertisingList in advertisingData"></div>
            </div> -->
        </div>
    </div>
</body>

</html>
<script src="../../script/api.js" charset="utf-8"></script>
<script src="../../script/common/jquery-3.3.1.min.js" charset="utf-8"></script>
<script src="../../script/common/common.js" charset="utf-8"></script>
<script src="../../script/common/config.js" charset="utf-8"></script>
<script src="../../script/common/vue.min.js" charset="utf-8"></script>
<script src="../../script/aui/aui-slide.js" charset="utf-8"></script>

<script type="text/javascript">
    var stateBarH;
    apiready = function() {
        api.parseTapmode();
        //沉浸式状态栏
        var systemType = api.systemType;
        var statusBar = api.require('statusBar');
        if (systemType == "ios") {
            if (navigator.userAgent.indexOf("iPhone") != -1) {
                stateBarH = api.safeArea.top;

                $("#header").css({
                    "paddingTop": api.safeArea.top + 'px'
                });
            }
        } else {
            statusBar.getStatusBarHeight(function(ret, err) {
                stateBarH = ret.statusHeight;
                $("#header").css({
                    "paddingTop": ret.statusHeight
                });
            });
        }

        vm.init();
    }

    var vm = new Vue({
        el: "#app",
        data: {
            userRegion: {},
            bannerData: [],
            noticeData: [],
            advertisingData: [],
            pages: 1
        },
        methods: {
            init() {
                this.userRegion = get_local('user_region');
                this.getBannerData();
                this.getNoticeData();
                this.page();
                this.getadvertisingData();
            },
            getBannerData() {
                var self = this;
                _ajax(Config.api.IndexHomeGetBanner, {}, function(res) {
                    if (res.code === 200) {
                        self.bannerData = res.data;
                        setTimeout(function() {
                            //幻灯特效
                            var slide = new auiSlide({
                                container: document.getElementById("aui-slide"),
                                "height": 190,
                                "speed": 500,
                                "autoPlay": 3000, //自动播放
                                "loop": true,
                                "pageShow": true,
                                "pageStyle": 'dot',
                                'dotPosition': 'center'
                            });
                        }, 200)
                    }
                });
            },
            getNoticeData() {
                var self = this;
                _ajax(Config.api.HomeGetBulletin, {}, function(res) {
                    if (res.code === 200) {
                        self.noticeData = res.data;
                        setTimeout(function() {
                            // 公告
                            var notice_slide = new auiSlide({
                                container: document.getElementById("notice-slide"),
                                "height": $('#notice-slide').height(),
                                "speed": 500,
                                "autoPlay": 3000, //自动播放
                                "loop": true,
                                "pageShow": false,
                            });
                        }, 200)
                    }
                });
            },
            getadvertisingData() {
                var self = this;
                _ajax(Config.api.HomeGetAdvert, {
                    pages: self.pages
                }, function(res) {
                    if (res.code === 200) {
                        if (res.data.length === 0) {
                            $toast('数据已加载完毕');
                            self.pages = -1;
                        } else {
                            self.advertisingData = self.advertisingData.concat(res.data);
                        }
                    }
                })
            },
            page() {
                var self = this;
                //上拉加载
                push_up(function() {
                    if (self.pages === -1) {
                        $toast('数据已加载完毕');
                    } else {
                        ++self.pages;
                        self.getadvertisingData();
                    }
                });
            },
            openCity() {
                var url = '../city/city_win.html';
                api.openFrame({
                    name: 'mask',
                    url: url,
                    rect: {
                        x: 0,
                        y: stateBarH,
                        w: 'auto',
                        h: 'auto'
                    },
                    bgColor: 'rgba(0,0,0,0.5)',
                    pageParam: {
                        name: api.winName,
                        frameName: api.frameName,
                        provinceid: this.userRegion.provinceid,
                        cityid: this.userRegion.cityid,
                        areaid: this.userRegion.areaid,
                    }
                });
            },
            lookingForWorkers() {
                var jsfun = 'setSelectOption(1);';
                api.execScript({
                    name: 'main',
                    script: jsfun
                });
            },
            openAdvertising(param) {
                open_w('advertising_win', './advertising/advertising_win.html', param);
            }
        }
    })

    function setCity(province, city, area) {
        var data = {
            "provinceid": province.code,
            "province": province.name,
            "cityid": city.code,
            "city": city.name,
            "areaid": area.code,
            "area": area.name
        };
        vm.userRegion = data;
    }
</script>
